<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('编辑补货单')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <input type="hidden" class="layui-input" th:value="${id}" id="inputID" name="id">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
        <form id="form1" class="layui-form layui-form-pane" action="" style="width: 100%;height: 100%">
            <div class="layui-form-item" id="simplewizardinwidget-steps">
                <div class="layui-col-xs24" id="edittext" style="display: none">
                    <div class="layui-form-item" style="position: absolute;right: 34em;top: 19em;background:#F0F0F0;height:10em;">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="line-height: 35px;">货品名称</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="phone" lay-verify="required" id="hpmc" autocomplete="off" class="layui-input layui-disabled" disabled>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="line-height: 35px;">补货数量</label>
                            <div class="layui-input-inline">
                                <input type="text" name="email"  id="bhsl" lay-verify="negative" autocomplete="off" class="layui-input" >
                            </div>
                        </div>
                        <!--<div class="layui-form-item">-->
                            <!--<label class="layui-form-label">请输入邮件</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<input type="text" placeholder="请输入邮件" lay-verify="required" class="layui-input" id="emailID">-->
                            <!--</div>-->
                        <!--</div>-->
                        <a class="layui-btn" id="editSave" lay-submit="" lay-filter="demo1">保存</a>
                    </div>
                </div>
            </div>
        </form>
        <!--<div class="layui-row layui-col-space30">-->

        <!--</div>-->
    </div>
</div>
</body>


<div th:include="public/public_js::public_js"></div>
<style type="text/css">

</style>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        });
        $("#load").on("click",function(){
            //console.log(123);
            var data = {
                ids:[],
                page:0,
                rows:10
            };
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:9191/zxsdwms/WmsDeliveryDetailsController/ShippingdetailsExcel", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            xhr.send(JSON.stringify({
                "ids": [],
                "page":0,
                "rows":10
            }));
        })
    });
    layui.use(['list','layer','zzpUtils','jquery','laydate'],function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate;
        window.operateEvent = {
            "click #edit": function (e, value, row, index) { //行按钮编辑
                editRow(row);
            },
        };
        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        })
        laydate.render({
            elem: '#test6'
            , theme: '#20a0ff'
        })
        var id = $('#inputID').val();
        console.log('intpuid', id);
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            showColumns: false,
            pagination: true,
//            url: '/wmsorderrepair/getDetailList/',
            columns: [
                {
                    field: 'hpmc',
                    title: '货品名称'
                }, {
                    field: 'bhsl',
                    title: '补货数量'
                },{
                    field: 'caozuo',
                    title: '操作',
                    events: operateEvent,
                    formatter: operateFormatter
                }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }

        });
            // 获取 查看补货任务的数据
        $(function () {
            console.log(666666);
            $.ajax({
                url: "/zxsdwms/wmsorderrepair/getDetailList/",
                type: "POST",
                dataType: "JSON",
                contentType: 'application/json',
                async: false,
                data:JSON.stringify({id:id}),
                success: function (data) {
                    console.log(666666, data);
                    $table.bootstrapTable('append', data);
                },
                error: function () { console.log("Error"); }
            });
        })

        function operateFormatter(value, row, index) {
                return [
                    '<a class="layui-btn layui-btn-primary layui-btn-xs" id="edit" >编辑</a>',
                ].join('')
        }
//        $('#edit').click(function editRow (value, row) {
//            console.log('value', value);
//            console.log('row', row);
//            $('#edittext').css('display', 'block');
//        })
        // 查看补货任务，编辑
        var rowID;
        function editRow (row) {
            console.log('rwo12rwo',row);
           $('#edittext').css('display', 'block');
            console.log('货品名称', row.hpmc);
            console.log('补货数量', row.bhsl);
            rowID = row.id;
            $('#hpmc').val(row.hpmc);       // 货品名称
            $('#bhsl').val(row.bhsl);       //补货数量
        }
        // 查看补货任务，保存

            form.on("submit(demo1)", function (data) {
                $('#hpmc').val();       // 货品名称
            $('#bhsl').val();       //补货数量
            console.log('hpbhVALUE',$('#bhsl').val());
            $.ajax({
                url: "/zxsdwms/wmsorderrepairdetailed/edit",
                type: "POST",
                dataType: "JSON",
                contentType: 'application/json',
                async: false,
                data:JSON.stringify({id:rowID,bhsl:$('#bhsl').val()}),
                success: function (data) {
                    console.log(666666, data);
//                    alert(data);
                    if (data) {
                        layer.msg(data.title + data.message);
                    }
                    setTimeout(function () {
                        history.go(0);
//                        $('#edittext').css('display', 'none');
                    }, 1000);
                },
                error: function () { console.log("Error"); }
            });
        })
//        $(".inline-search-btn").on('click', function () {
//            zzpUtils.refreshTable("#table");
//        })
    });
</script>
</html>